﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace ExcelImport.Validators
{
    public class ValueMappingProcessor : IDataRowProcessor
    {
        public void Run(DataRow row, PipelineContext context)
        {
            foreach (var importProperty in context.ImportTable.ImportProperties.Where(p => p.Ordinal.HasValue))
            {
                string value = row[importProperty.Ordinal.Value]?.ToString();

                if (importProperty.ValueMappings.TryGetValue(value, out object dest))
                {
                    row[importProperty.Ordinal.Value] = dest;
                }
            }
        }
    }
}
